class MainController < ApplicationController
  before_filter :login_required, :only => [:welcome]
  def index
    @body_id = "home"
    if logged_in?
        redirect_to(:action => 'welcome') and return
    end
    @most_comment_leechdoms = Comment.find(:all, :order => "leechdom_id", :limit => 20)
    @comments = Comment.find(:all, :order => "id DESC", :limit => 10)
  end
  
  def welcome
    @body_id = "home"
    @most_comment_leechdoms = Comment.find(:all, :order => "leechdom_id", :limit => 20)
    @comments = Comment.find(:all, :order => "id", :limit => 10)
  end
  
  def blog
    @body_id = "home"
  end
  
  def search
    @body_id = "leechdoms"
    @word = params[:keyword]
    if params[:type] == "1"
      @leechdoms = CnLeechdom.paginate :page => params[:page], :per_page => 30, :conditions => ["cpmc like ? or spm like ?","%#{params[:keyword]}%","%#{params[:keyword]}%"]
      @type = "1"
    else
      @leechdoms = InterLeechdom.paginate :page => params[:page], :per_page => 30, :conditions => ["cpmczw like ? or spmzw like ?","%#{params[:keyword]}%","%#{params[:keyword]}%"]
      @type = "2"
    end
  end
end
